package lab2;

import java.util.Random;


public class Test extends Thread{

	String name;
	Semafor s;
	
	Test(String name,Semafor sem){
		this.name=name;
		s=sem;
	}
	
	public void run(){
		
		Random r=new Random();
		
		for (int i=0;i<100;i++){
			s.opusc();
			System.out.println("##################################"+name+"######################################");
			try {
				sleep(Math.abs(r.nextInt(MAX_PRIORITY)));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			s.podnies();
		}
		
	}
	
	
	public static void main(String[] args) {
		
		
		Semafor s = new Semafor(1);
		
		Test A = new Test("WATEK1",s);
		A.start();
		Test B = new Test("WATEK2",s);
		B.start();

		try {
			A.join();
			B.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

